// console.log('999 :>> ', 999)
//公共样式
require('../../assets/css/common.less')
require('../../assets/fonts/font-duicuo/iconfont.css')
// 引入自己的样式
require('./login.less')
////引入axios工具函数
const request=require('../../utils/request')

let phone = document.querySelector('#phone')
let psd = document.querySelector('#psd')
let submit = document.querySelector('#submit')
submit.addEventListener('click', () => {
    let msg = ''
    if (!/^1[3-9]\d{9}$/.test(phone.value)) {
        msg = '手机号错误'
        console.log(msg);
    } else if (!/^\w{3,6}$/.test(psd.value)) {
        msg = '密码格式错误'
        console.log(msg);

    } else {
        console.log('验证通过');
        request.post('/api/user/login',{
            account:phone.value,
            password:psd.value
        }).then(res=>{
            console.log(res.data);
            //结构数据
            const {errno,data}=res.data;
            if(errno===0){
                //操作数据
                localStorage.setItem('token','Bearer '+data.token)
                location.href='./home.html'

            }
        })

    }
    if(msg){
        alert(msg)
    }
})
